/*
 * @Author: 
 * @Date: 2025-06-11 14:11:58
 * @LastEditTime: 2025-06-11 14:50:52
 * @Description: 
 */
import 'package:flutter/material.dart';
import '../models/inventory.dart';
import '../models/order.dart';
import '../models/task.dart';

class WmsService with ChangeNotifier {
  List<InventoryItem> _inventory = [];
  List<Order> _orders = [];
  List<Task> _tasks = [];

  List<InventoryItem> get inventory => _inventory;
  List<Order> get orders => _orders;
  List<Task> get tasks => _tasks;

  Future<void> fetchInventory() async {
    // 模拟API调用
    await Future.delayed(const Duration(seconds: 1));
    
    _inventory = [
      InventoryItem(
        id: '1',
        name: '照明吊灯',
        sku: 'IS-1291299312',
        location: 'AJ2-03-21',
        quantity: 100,
        unit: '箱',
      ),
      // 更多库存项...
    ];
    
    notifyListeners();
  }

  Future<void> fetchOrders() async {
    // 模拟API调用
    await Future.delayed(const Duration(seconds: 1));
    
    _orders = [
      Order(
        id: 'PO-10007-110021',
        type: '采购订单',
        status: '处理中',
        items: [
          OrderItem(
            id: '1',
            sku: 'IS-1291299312',
            name: '照明吊灯',
            quantity: 100,
            unit: '箱',
          ),
        ],
      ),
      // 更多订单...
    ];
    
    notifyListeners();
  }

  Future<void> fetchTasks(String userId) async {
    // 模拟API调用
    await Future.delayed(const Duration(seconds: 1));
    
    _tasks = [
      Task(
        id: 'T-001',
        type: '拣货',
        status: '待处理',
        orderId: 'PO-10007-110021',
        itemId: 'IS-1291299312',
        quantity: 100,
        location: 'AJ2-03-21',
        assignedTo: userId,
      ),
      // 更多任务...
    ];
    
    notifyListeners();
  }

  Future<void> completeTask(String taskId) async {
    // 模拟API调用
    await Future.delayed(const Duration(seconds: 1));
    
    final index = _tasks.indexWhere((task) => task.id == taskId);
    if (index != -1) {
      // _tasks[index] = _tasks[index].copyWith(status: '已完成');
      notifyListeners();
    }
  }
}